'use strict';

var mongoose = require('mongoose');
var modelPlugin = require("../model.plugin");
var Schema = mongoose.Schema;
var ObjectId  = Schema.ObjectId;

/*var operatorSchema = new Schema({
  name: {type: String},
  icon: {type: String},
  action: {type: String},
  state: {type: Number}
});*/

var menuSchema = new Schema({
  name: {type: String, required: true},
  feature: {type: String, required: true, unique: true},
  //{0: userMenu, 1: systemMenu, 2: others}
  menuType: {type: Number, enum:[0, 1, 2], default: 0},
  //{0: disable, 1: used, 2: ...}
  state: {type: Number, enum:[0, 1, 2], default: 1},
  sort: {type: Number, default: 0},
  description: {type: String},
  action: {type: String},

  createdAt: {type: Date, default: Date.now},
  createdBy: {type: ObjectId, ref: 'User'},
  updatedAt: {type: Date, default: Date.now},
  updatedBy: {type: ObjectId, ref: 'User'}

  /*operatorList: [{
    name: {type: String},
    icon: {type: String},
    action: {type: String},
    //{0: disable, 1: used, 2: ...}
    state: {type: Number, enum:[0, 1, 2], default: 1}
  }]*/
});

menuSchema.plugin(modelPlugin);
menuSchema.index({feature: 1});

mongoose.model('Menu', menuSchema);
